#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStringList>
#include <map>
#include "console.hpp"
#include "dictionary.hpp"



namespace Ui
{
    class MainWindow;
}



class MainWindow : public QMainWindow
{
    Q_OBJECT

public:

    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QPushButton* area[11][11];
    Console console;



private slots:

    void newGame();

    void on_text_area_blockCountChanged(int newBlockCount);



private:

    Ui::MainWindow *ui;
    map<QString, QString> dictionary;



    void createDictionary(string file_name)
    {
        ifstream file;
        file.open(file_name);
        if (!file.is_open())
        {
            Dictionary::createFile(file_name);
            file.open(file_name);
            if (file.is_open())
            {
                createMap(file);
                file.close();
            }
        }
        else
        {
            createMap(file);
            file.close();
        }
    }



    void createMap(ifstream &file)
    {
        string line;
        QString l;
        QStringList words;
        while (getline(file, line))
        {
            l = QString::fromStdString(line);
            words = l.split("\t");
            dictionary[words[0]] = words[1];
        }
        file.close();
    }



    bool anyFunctionEquals(QString keyword, QString* functions, int n)
    {
        int i = 0;
        bool equals = 0;
        while (i < n && !equals)
        {
            if (functions[i] == keyword)
            {
                equals = 1;
            }
            i++;
        }
        return equals;
    }
};

#endif // MAINWINDOW_H
